Quiero crear una validación de archivo que no sea obligatoria, pero cuando se inserta, debe ser un archivo zip y un tamaño máximo de 2 MB. Uso Codeigniter 4 & Js, con el siguiente código, cuando la entrada [archivo] está vacía, todavía recibo un error de validación.
$("#btnReply").click(function(e) { var frmReply = new FormData(); frmReply.append('attachment_reply', $('#attachment_reply')[0].files[0]); e.preventDefault(); $.ajax({ type: 'POST', url: 'http://localhost/syst20/ticketreply/store', enctype: 'multipart/form-data', dataType: 'json', data: frmReply, });Mi regla de controlador
if (!$this->validate([ 'attachment_reply' => [ 'label' => 'Attachment', 'rules' => 'ext_in[attachment_reply,zip,rar,7z]|max_size[attachment_reply,2000]', ]])) { $error_description = $this->validator->getErrors(); $callback = array( 'status' => 'failed', 'message' => $error_description, 'ticket_id' => $ticket_id, 'token' => csrf_hash(), ); }